Skip to main content

All Questions

1vote
2answers
213views

Redirect to a filename that will be a variable and contain a command substitution

I'm using nmap to scan a network and then create an XML file that contains the scanned information. I want that XML file to contain the date of the scan so that each file is unique and I can see the ...
johnmacward's user avatar
0votes
2answers
248views

How to get the Path difference and store it in a variable

Suppose I have two paths. Path1 which is static and path2 which is dynamic. Example: Path1= /tmp/folder/ Path2= /tmp/folder/dir1/dir1_2 Result: Diff= /dir/dir1_2 I want to achieve as above example....
Asif Ahmed's user avatar
7votes
3answers
868views

Remove repeating string pattern from variable with POSIX parameter expansion

I wanted to use 2.6.2 Parameter Expansion to remove leading characters from a string, but was surprised to find out that "Remove Largest Prefix Pattern" doesn't automatically repeat the ...
finefoot's user avatar
9votes
2answers
793views

In POSIX scripting, is x=$y always equivalent to x="$y"?

Are x=$y and x="$y" always equivalent? Didn't know how to search for this. So far, I've always been using x="$y" to be "on the safe side". But I used x=$1 at one point ...
finefoot's user avatar
4votes
2answers
6kviews

How to dynamically set a variable name in shell script?

I am looking for a sh equivalent of the following (yes, really.) #!/bin/bash exe1='filepath' n=1 var=exe${n} echo ${!var} Where the echo should output filepath. I want to use plain sh. I have ...
kaiya's user avatar
0votes
1answer
101views

problem with dynamic variable on a bash script

I would like to obtain a .txt file of the following format: chr1: 3 chr2: 3 chr3: 3 I use the following script but give different errors: #!/bin/bash touch number_samples.txt for i in {10..22} do ...
Will's user avatar
  • 117
1vote
4answers
989views

Add Space Before Last Character in Variable

I have a variable that contains some numbers then a letter example: 242M I need to add a space right before the last character in that variable so that when echo'd it would look like 242 M I've ...
RyanL's user avatar
0votes
2answers
8kviews

Bash-Script: How to insert Variables into Bash-Script?

The following bash script is working completely fine: #!/bin/bash echo '!PaSsWoRd!' | openconnect --csd-wrapper=/home/user/.cisco/csd-wrapper.sh --authenticate --user=abcde123 --authgroup="tunnel My ...
Dave's user avatar
  • 1,046
3votes
1answer
5kviews

In bash, how can I export/set a global variable from a read funtion inside a script, for use in a second script and a config file later on?

For example. I have 2 discrete scripts, which I want to remain and run separately. Script 1 utilizes a read function asking for a desired filename lets just say name1, does it's thing, and outputs the ...
CharlieTango92's user avatar
0votes
1answer
171views

How to make variables be accessible from scripts [closed]

In Ubuntu 16.04 I executed a script (script 1) which by itself executes two other scripts (script 2 and script 3). Script 3 contains a variable substitution (${x}) for a variable already declared in ...
user273439's user avatar
1vote
1answer
536views

pass the value of variable from a script to another script from another server

I have a script that will ssh to another server. Script A will get the value of $variableA, then will ssh to another server to execute a script B which will need the value of $variableA. I tried ...
oakley00's user avatar
1vote
1answer
784views

For with read value

In what way does the final value of number being assigned by read var number (and we enter 5) and number=5 differ? I was making this for loop: read var number #number=5 factorial=1 i=1 for i in `seq ...
Peter's user avatar
0votes
1answer
27kviews

Checking if string exists in file with cat | grep

Good day all Purpose: checking if a string exists in a file and running actions accordingly if [ -z 'sudo cat /etc/sudoers | grep "$USER ALL=(ALL) NOPASSWD:ALL"' ]; echo "no output, cont." || echo "...
CybeX's user avatar
2votes
1answer
596views

I want to use the variable declared inside an SSH session to be used locally in my shell script

Whenever I try to use the variable declared inside my SSH session it gives me blank output. Here is the code which I am trying to execute: ssh -T host <<\HERE export usage1=$(df -h |grep /nas/...
Aishwarya Jhawar's user avatar
659votes
4answers
506kviews

Using "${a:-b}" for variable assignment in scripts

I have been looking at a few scripts other people wrote (specifically Red Hat), and a lot of their variables are assigned using the following notation VARIABLE1="${VARIABLE1:-some_val}" or some expand ...
Justin Garrison's user avatar

153050per page
close